package com.taoist_awei.blog.core;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ClassifyNode {
    private String classifyId;

    private String classifyName;

    private List<ClassifyNode> childList = new ArrayList<>();

    private String fatherId;

    private Integer articleNum;

    public ClassifyNode(String classifyId) {
        this.classifyId = classifyId;
        this.childList = null;
    }

    public ClassifyNode(String classifyId, String classifyName, String fatherId, Integer articleNum) {
        this.classifyId = classifyId;
        this.classifyName = classifyName;
        this.fatherId = fatherId;
        this.articleNum = articleNum;
    }

    public ClassifyNode(String classifyId, List<ClassifyNode> childList) {
        this.classifyId = classifyId;
        this.childList = childList;
    }

    public ClassifyNode() { }

    public void addChild(ClassifyNode node) {
        if (this.childList == null) {
            this.childList = new ArrayList<>();
        }
        this.childList.add(node);
    }

    @Override
    public boolean equals(Object obj) {
        ClassifyNode another = (ClassifyNode) obj;
        return this.classifyId.equals(another.classifyId);
    }
}
